<?php
if (!defined('INDEX')) exit;
require("common/functions_jcas_modules.php");
?>
<table width="100%"  border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td class="datatd" bgcolor="#FFFFFF"><?php echo $lang['language_desc']?></td>
  </tr>
</table>
<br />
<?php
####### ACTIONS ########
// Add new variable
echo language_insert();
// Edit variable
echo language_update();
// Set value for field
echo common_set_value($tbl['language'],'id');
// Delete variable
echo common_delete($tbl['language'],'id');
// Delete selected variables
echo common_delete_selected($tbl['language'],'id');
// Update variable
echo common_update_sort($tbl['language'],'id','sort');
// Active selected
echo common_activate_selected($tbl['language'],'id','active');
// Deactive selected
echo common_deactivate_selected($tbl['language'],'id','active');

if($show_content)
{
?>

		<table width="100%"  border="0" cellspacing="0" cellpadding="0">
	  <tr>
		 <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
			<tr>
			  <td width="120" class="<?php echo ((@$_GET['p']=='show')?'tabtd':'tabtd_blur')?>" align="center"><a href="<?php echo $index_url?>&p=show"><?php echo $lang['manage_language']?></a></td>
			  <td width="5">&nbsp;</td>
			  <td width="120" class="<?php echo ((@$_GET['p']=='add')?'tabtd':'tabtd_blur')?>" align="center"><a href="<?php echo $index_url?>&p=add"><?php echo $lang['add_language']?></a></td>
			  <td width="5">&nbsp;</td>
			  <td >&nbsp;</td>
			</tr>
		 </table></td>
	  </tr>
	  <tr>
		 <td class="tabtd" height="5"></td>
	  </tr>
	</table>
<?php
switch(@$_GET["p"])
{
	case "show":
	default:
		$q_language = @$DB->query('SELECT * FROM '.$tbl['language'].' ORDER BY sort ASC, updated_time DESC');
		$num_language = $DB->num_rows($q_language);
		?>

		<table width="100%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
		<form name="frm_show" method="post" action="<?php echo $index_url?>&p=show">
			<tr>
				<td colspan="20" class="headtd"><?php echo $lang["language_title"]?></td>
			</tr>
			<tr align="center">
				<td width="20"  class="subheadtd"><?php echo $lang['order']?></td>
				<td width="20"  class="subheadtd"><?php echo $lang['id']?></td>
				<td width="20" class="subheadtd"><?php echo $lang['flag']?></td>
				<td class="subheadtd"><?php echo $lang['title']?></td>
				<td width="100" class="subheadtd"><?php echo $lang['language_code']?></td>
				<td width="60" class="subheadtd"><?php echo $lang['default']?></td>
				<td width="40" class="subheadtd"><?php echo $lang['sort']?></td>
				<td width="50" class="subheadtd"><?php echo $lang['active']?></td>
				<td width="80" class="subheadtd"><?php echo $lang['date']?></td>
				<td width="60" class="subheadtd"><input type="checkbox" name="all_id" class="box" value="all" onClick="set_all_cb('frm_show','id[]','all_id');" title="<?php echo $lang['check_uncheck_all']?>"></td>
			</tr>
			<?php
			if($num_language)
			{
				$no = 0;
				for($x=0;$x<$num_language;$x++)
				{
					$no += 1;
					$language = $DB->result_array($q_language,$x,"id,admin_id,sort,title,code,is_default,created_by,created_time,updated_by,updated_time,active");
					$language_title = common_status_title($language['created_by'], timestamp($language['created_time']), $language['updated_by'], timestamp($language['updated_time'])); 
					?>
					<tr  onMouseOver="rollon(this);" onMouseOut="rolloff(this);">
						<td align="center" class="datatd"><?php echo $no?></td>
						<td align="center" class="datatd"><font color="red"><?php echo $language['id']?></font></td>
						<td class="datatd" align="center"><img src="images/flag/flag_<?php echo $language['code']?>.gif" /></td>
						<td class="datatd"><a href="<?php echo $index_url?>&p=edit&id=<?php echo $language['id']?>" title="<?php echo $language_title?>"><b><?php echo $language['title']?></b></a></td>
						<td class="datatd" align="center"><font color="red"><?php echo $language['code']?></font></td>
						<td align="center" class="datatd">
							 <?php echo html_yes_no($language['is_default'],'is_default',$index_url.'&p=show&id='.$language['id']) ?>
						</td>
						<td align="center" class="datatd"><input type="text" name="sort[<?php echo $language['id']?>]" size="3" value="<?php echo $language['sort']?>" style="color:#FF0000; text-align:right" /></td>
						<td align="center" class="datatd">
							 <?php echo html_yes_no($language['active'],'active',$index_url.'&p=show&id='.$language['id']) ?>
						</td>
						<td align="center" class="datatd"><?php echo show_date($cfg['date_format'],timestamp($language['updated_time']))?></td>
						<td align="center" class="datatd">
							<?php echo html_icon_edit($index_url.'&p=edit&id='.$language['id']) ?>
							<?php echo html_icon_delete($index_url.'&p=show&act=delete&id='.$language['id']) ?>
							<?php echo html_input_checkbox('id',$language['id']) ?>
						</td>
				  </tr>
				<?php
				}
			}
			else 
			{
				?><tr>
					 <td colspan="20" align="center" class="datatd"><?php echo message($lang['no_requested_data'],'info')?></td>
				  </tr>
				<?php
			}
			?>
			<tr>
				 <td colspan="20">
					 	<table width="100%"  border="0" cellpadding="0" cellspacing="0">
						<tr align="center">
						  <td  align="right" class="row1td">&nbsp;</td>
							 <td width="10%" class="row1td"><input type="submit" name="update_sort" value="<?php echo $lang["update_sort"]?>" class="button"></td>
						  <td width="10%" class="row1td"><?php echo common_action_list()?></td>
						</tr>
					  </table>
						
					 </td>
				  </tr>
				  <input type="hidden" name="session_id" value="<?php echo session_id()?>">
		  </form>
</table>
		<?php
		break;
		
		case "add":
		case "edit":
		$language = $DB->fetch_array($DB->query('SELECT * FROM '.$tbl['language'].' WHERE id="'.$_GET['id'].'"'));
		echo js_validate("title,code","frm_add");
		?>
		<table width="100%"  border="0" cellspacing="0" cellpadding="0" align="center">
				<form name="frm_add" method="post" action="<?php echo $index_url?>&p=add&id=<?php echo $_GET['id']?>" onSubmit="return validate_frm_add();">
				  <tr>
					 <td colspan="2" class="headtd"><?php echo (($language)?$lang['edit_language']:$lang['add_language'])?></td>
				  </tr>
				  <tr >
					 <td width="30%" class="row1td"><b><?php echo $lang['title']?> </b>*</td>
				  <td width="70%" class="row2td"><input name="title" type="text" size="30" style="width:30%" value="<?php echo (($language)?$language["title"]:post("title"))?>" ></td>
				  </tr>
				  
				  <tr >
					 <td class="row1td"><b><?php echo $lang['language_code']?></b> *</td>
					 <td class="row2td"><input name="code" type="text" size="30" style="width:10%" value="<?php echo (($language)?$language["code"]:post("code"))?>" ></td>
				  </tr>
				  <tr >
				    <td valign="top" class="row1td"><b><?php echo $lang['is_default_language']?></b></td>
				    <td class="row2td"><input type="checkbox" class="box"  name="is_default" value="1"  <?php echo (($language)?(($language['is_default'])?'checked=true':''):'')?> /></td>
			      </tr>
				  
				  <tr>
					 <td valign="top" class="row1td"><b><?php echo $lang['active']?></b></td>
					 <td class="row2td"><input type="checkbox" class="box"  name="active" value="1"  <?php echo (($language)?(($language['active'])?'checked=true':''):'checked=true')?> /></td>
				  </tr>
				  
				  <tr>
					 <td colspan="2" align="center" valign="top" class="row2td">
					 <?php if($language) { ?>
					 	 <input type="submit" name="update" class="button" value="<?php echo $lang['btn_update']?>">
						 <input type="reset"  class="button" value="<?php echo $lang['btn_reset']?>">
					 <?php } else { ?>
					  	<input type="submit" name="insert" class="button" value="<?php echo $lang['btn_insert']?>">
					 <?php } ?>					 </td>
				  </tr>
					 <input type="hidden" name="session_id" value="<?php echo session_id()?>">
		  </form>
				</table>
			<?php
	break;
}// end switch
}// end show_content
$_GET["p"] = false;
?>